<template>
  <!-- 收入/支出 -->
  <el-container>
    <el-main>
      <div class="selectBox">
        <el-date-picker
          v-model="time"
          type="month"
          placeholder="请选择日期"
          @change="changeTime"
          value-format="YYYY-MM"
        />
        <p class="name">收入支出明细</p>
      </div>
      <div class="container">
        <div class="totalList">
          <div class="row">
            <div class="item item1">
              <div class="title">
                <img
                  :src="require('/public/img/finance/icon1.webp')"
                  alt=""
                  class="icon"
                />
                <p>总收入</p>
              </div>
              <p class="year">{{ year }}年</p>
              <div class="money">
                <p class="value">￥</p>
                <p class="num">{{ totalMoney.incomeMoney }}</p>
              </div>
            </div>
            <div class="item item2">
              <div class="title">
                <img
                  :src="require('/public/img/finance/icon2.webp')"
                  alt=""
                  class="icon"
                />
                <p>总支出</p>
              </div>
              <p class="year">{{ year }}年</p>
              <div class="money">
                <p class="value">￥</p>
                <p class="num">{{ totalMoney.outcomeMoney }}</p>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="item item3">
              <div class="title">
                <img
                  :src="require('/public/img/finance/icon3.webp')"
                  alt=""
                  class="icon"
                />
                <p>总利润</p>
              </div>
              <p class="year">{{ year }}年</p>
              <div class="money">
                <p class="value">￥</p>
                <p class="num">{{ totalMoney.profitMoney }}</p>
              </div>
            </div>
            <div class="item item4">
              <div class="title">
                <img
                  :src="require('/public/img/finance/icon3.webp')"
                  alt=""
                  class="icon"
                />
                <p>{{ month }}月利润</p>
              </div>
              <p class="year">{{ year }}年</p>
              <div class="money">
                <p class="value">￥</p>
                <p class="num">{{ totalMoney.profitMonthMoney }}</p>
              </div>
            </div>
          </div>
        </div>
        <div class="list">
          <div class="row">
            <div class="item item1" @click="type = 1">
              <div class="content">
                <div class="title">
                  <img
                    :src="require('/public/img/finance/icon4.webp')"
                    alt=""
                    class="icon"
                  />
                  <p>{{ month }}月收入</p>
                </div>
                <p class="num">{{ totalMoney.incomeMonthMoney }}</p>
              </div>
            </div>
            <div class="item item2" @click="type = 2">
              <div class="content">
                <div class="title">
                  <img
                    :src="require('/public/img/finance/icon5.webp')"
                    alt=""
                    class="icon"
                  />
                  <p>{{ month }}月付款</p>
                  <p class="num">{{ totalMoney.paymentMonthMoney }}</p>
                </div>
              </div>
            </div>
          </div>
          <div class="row">
            <div class="item item3" @click="type = 3">
              <div class="content">
                <div class="title">
                  <img
                    :src="require('/public/img/finance/icon6.webp')"
                    alt=""
                    class="icon"
                  />
                  <p>{{ month }}月报销</p>
                </div>
                <p class="num">{{ totalMoney.reimburseMonthMoney }}</p>
              </div>
            </div>
            <div class="item item4" @click="type = 4">
              <div class="content">
                <div class="title">
                  <img
                    :src="require('/public/img/finance/icon7.webp')"
                    alt=""
                    class="icon"
                  />
                  <p>{{ month }}月借款</p>
                  <p class="num">{{ totalMoney.loanMonthMoney }}</p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
      <el-main class="nopadding itemList">
        <income-list
          ref="incomeList"
          :time="time"
          v-show="type == 1"
        ></income-list>
        <payment-list
          ref="paymentList"
          :time="time"
          v-show="type == 2"
        ></payment-list>
        <reimburs-list
          ref="reimbursList"
          :time="time"
          v-show="type == 3"
        ></reimburs-list>
        <loan-list ref="loanList" :time="time" v-show="type == 4"></loan-list>
      </el-main>
    </el-main>
  </el-container>
</template>
<script>
import incomeList from './components/incomeList.vue'
import paymentList from './components/paymentList.vue'
import reimbursList from './components/reimbursList.vue'
import loanList from './components/loanList.vue'
export default {
  name: 'incomeAndPayment',
  components: {
    incomeList,
    paymentList,
    reimbursList,
    loanList
  },
  data () {
    return {
      time: this.$TOOL.dateFormat(new Date(), "yyyy-MM"),
      year: this.$TOOL.dateFormat(new Date(), "yyyy"),
      month: this.$TOOL.dateFormat(new Date(), "MM"),
      totalMoney: [],//收入/支出总金额
      type: 1
    }
  },
  mounted () {
    this.getTotalMoney()
  },
  methods: {
    // 选择日期
    changeTime (val) {
      this.year = this.$TOOL.dateFormat(this.time, "yyyy")
      this.month = this.$TOOL.dateFormat(this.time, "MM")
      this.getTotalMoney()
      // this.$nextTick(() => {
      //   this.$refs.incomeList.getData()
      //   this.$refs.paymentList.getData()
      //   this.$refs.reimbursList.getData()
      //   this.$refs.loanList.getData()
      // })
    },
    // 获取收入/支出总金额
    async getTotalMoney () {
      let { data } = await this.$API.reportForm.getFinanceMoney.get({
        time: this.time
      })
      this.totalMoney = data
      // this.getIncomeList()
    },
    // 获取月收入列表
    async getIncomeList () {
      let { data } = await this.$API.reportForm.getIncomeList.get({ tiem: this.time })
      this.itemList = data
    }
  }
}
</script>
<style lang='scss' scoped>
.el-main {
  padding: 25px;
}
.selectBox {
  display: flex;
  align-items: center;
  font-size: 18px;
  .name {
    font-weight: 600;
    margin-left: 10px;
  }
}
.container {
  display: flex;
}
.totalList {
  width: 60%;
  // display: flex;
  // flex-wrap: wrap;
  // align-items: center;
  // justify-content: space-between;
  margin-top: 20px;
  .item {
    position: relative;
    flex-basis: calc((100% / 2 - 20px));
    min-width: 280px;
    height: 280px;
    margin-right: 30px;
    margin-bottom: 20px;
    font-size: 16px;
    color: #fff;
  }

  .title {
    position: absolute;
    left: 15px;
    top: 20px;
    display: flex;
    align-items: center;
    font-size: 18px;
  }
  .icon {
    width: 46px;
    height: 46px;
    transform: scale(0.8);
  }
  .year {
    position: absolute;
    right: 20px;
    top: 15px;
  }
  .money {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    align-items: baseline;
    margin-top: 20px;
  }
  .num {
    font-size: 38px;
  }
  .item1 {
    background: url("/public/img/finance/img1.webp") no-repeat;
    background-size: 100% 100%;
    .year {
      color: #82c3da;
    }
  }
  .item2 {
    background: url("/public/img/finance/img2.webp") no-repeat;
    background-size: 100% 100%;
    .year {
      color: #dcad8c;
    }
  }
  .item3 {
    background: url("/public/img/finance/img3.webp") no-repeat;
    background-size: 100% 100%;
    .year {
      color: #8cd48d;
    }
  }
  .item4 {
    background: url("/public/img/finance/img4.webp") no-repeat;
    background-size: 100% 100%;
    .year {
      color: #3ccc97;
    }
  }
}
.row {
  display: flex;
  justify-content: space-between;
  width: 100%;
}

.list {
  width: 40%;
  margin-top: 20px;
  margin-right: 10px;

  .item {
    flex-basis: calc((100% / 2 - 20px));
    height: 280px;
    min-width: 200px;
    border-radius: 30px;
    margin-right: 30px;
    margin-bottom: 20px;
    color: #fff;
    cursor: pointer;
    &:nth-child(2n) {
      margin-right: 0;
    }
    &:hover {
      box-shadow: 4px 4px 6px 0px rgba(123, 40, 4, 0.05);
    }
  }
  .content {
    position: relative;
    width: 100%;
    height: 100%;
    padding: 20px;
    background-color: #fff;
    margin-left: 6px;
    border-radius: 30px;
    font-size: 16px;
  }
  .item1 {
    background-color: #00a2e7;
    color: #00a2e7;
  }
  .item2 {
    background-color: #01caa6;
    color: #01caa6;
  }
  .item3 {
    background-color: #ffa820;
    color: #ffa820;
  }
  .item4 {
    background-color: #dd4d0f;
    color: #dd4d0f;
  }
  .icon {
    width: 50px;
    height: 45px;
    transform: scale(0.8);
  }
  .title {
    display: flex;
    align-items: center;
  }
  .num {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    margin-top: 20px;
    font-size: 32px;
    color: #333;
  }
}

.itemList {
  padding: 0;
}

@media screen and (max-width: 1600px) {
  .totalList {
    // padding-right: 30px;
    .item {
      height: 200px;
    }
  }
  .list {
    // padding-left: 20px;
    .item {
      height: 200px;
    }
  }
}
</style>